Repository navigation
R23-T025: Monte Carlo Pi explainer, convergence experiment, and documentation - #116
Open
mohammedsohail0301-dot wants to merge 1 commit into
Open
mohammedsohail0301-dot wants to merge 1 commit into
mohammedsohail0301-dot wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
Checklist
Description
This pull request completes Task R23-T025: enhancing the documentation and empirical validation of Monte Carlo$\pi$ estimation in
maths/pi_monte_carlo_estimation.py.Key contributions include:
ValueErrorcheck remain intact and passing.work/R23-T025/EXPLAINER.md): Complete walkthrough with mathematical derivation, ASCII & Mermaid diagrams, a hand-worked 10-point simulation table, and recorded classmate feedback re-derivingestimate_pi(100, 1) == 3.2.work/R23-T025/error_vs_n_plot.png): Empirical demonstration of error convergence acrossType of Change
Changes Made
maths/pi_monte_carlo_estimation.py:abs(estimate_pi(50000, 42) - math.pi) < 0.01->True.100, 1,1000, 11,1000000, 111) and thenumber_of_simulations < 1raise path.work/R23-T025/:EXPLAINER.md: Comprehensive student guide covering mathematical foundations, worked example, classmate verification, and empirical findings.experiment.py: Simulation runner measuring convergence over 9 sample sizes and generating the log-log plot.error_vs_n_plot.png: Dual-curve log-log visualization showing alignment withtest_output.txt: Captured test execution logs.Empirical Convergence Summary
| Sample Size$N$ | Empirical Mean Error $|\hat{\pi} - \pi|$ | Theoretical $1/\sqrt{N}$ | Ratio |$0.059363$ | $0.100000$ | $0.59$ |$0.047281$ | $0.031623$ | $1.50$ |$0.013800$ | $0.010000$ | $1.38$ |$0.003951$ | $0.003162$ | $1.25$ |$0.000945$ | $0.001000$ | $0.95$ |
|---|---|---|---|
| 100 |
| 1,000 |
| 10,000 |
| 100,000 |
| 1,000,000 |
Testing & Verification
python3 -m doctest -v maths/pi_monte_carlo_estimation.py-> 4/4 doctests passed.uv run --with pytest pytest --doctest-modules maths/pi_monte_carlo_estimation.py-> 1 passed in 0.02s.uvx ruff check maths/pi_monte_carlo_estimation.py work/R23-T025/experiment.py-> All checks passed.uvx ruff format --check maths/pi_monte_carlo_estimation.py work/R23-T025/experiment.py-> 2 files already formatted.uvx ty check --exit-zero maths/pi_monte_carlo_estimation.py-> 0 diagnostics.Additional Notes
student/E26B07F0850/R23-T025-upstream(andR23-T025-upstream) containing only the changes inmaths/pi_monte_carlo_estimation.pyhas been created and pushed for a later upstream PR.